package cn.zn.base.common.utils;

import cn.hutool.core.date.DateUtil;
import cn.hutool.crypto.SecureUtil;

import java.util.Date;

public class SignUtil {

    /**
     * 签名
     *
     * @param code code
     * @param salt 盐值
     * @return 结果
     */
    public static String sign(String code, String salt) {
        String codeMd5 = SecureUtil.md5(code);
        Date date = DateUtil.date();
        String year = DateUtil.format(date, "yyyy");
        String month = DateUtil.format(date, "MM");
        String day = DateUtil.format(date, "dd");
        String dateStr = year + salt + month + salt + day;
        return SecureUtil.md5(dateStr + codeMd5);
    }

    public static String signToken(String code, String salt) {
        return code + "_" + sign(code, salt);
    }

    public static String singOA(String code) {
        Date date = DateUtil.date();
        String year = DateUtil.format(date, "yyyy");
        String month = DateUtil.format(date, "MM");
        String day = DateUtil.format(date, "dd");
        return code + "_" + SecureUtil.md5(code + year + month + day);
    }

}
